Date: Sat, 31 Mar 2007 23:11:20 -0500 From: Blargg:; To: anomie:; Subject: Re: S-DSP research I think I cracked the pathological timer behavior, at least for timer 2 (haven't tested the others, so who knows what's next). It's awfully twisted, but I've managed to emulated it closely. It turns out to be a great source of random bits. When you write a value other than 1, 2, 4, or 8 to T2TARGET just after the presaler clocks the internal divider and the divider's new value matches the period you've written, the glitch *might* occur. The probability is nearly 100% unless the new period is 3, 5, or 9. In that case, it depends on the previous period and the new period (see tables below). If the probability results in the glitch occurring, it *decrements* the divider by the value of the lowest set bit in the new period, i.e. if the new period is 0x14, it decrements the divider by 4. Here are the probabilities (100=always occurs) for periods 3, 5, and 9, indexed by the previous period. As noted, it's > 99% for the other cases. Period 3 0 1 2 3 4 5 6 7 8 9 A B C D E F ---------------------------------------------------------------- 77 100 100 100 82 57 36 11 86 61 45 9 80 36 22 4 | 0 88 61 46 9 81 46 27 5 81 43 29 5 64 23 11 3 | 1 86 63 51 10 85 45 24 6 80 46 32 4 65 28 11 4 | 2 86 45 33 6 64 25 13 2 61 25 13 3 39 12 6 1 | 3 87 66 52 12 83 52 29 6 81 43 29 6 70 28 12 2 | 4 85 47 32 7 72 29 14 3 67 27 16 3 49 16 6 3 | 5 80 48 29 6 70 31 14 3 68 26 17 3 53 16 7 3 | 6 68 28 12 4 46 13 10 2 46 13 8 2 27 7 4 1 | 7 91 68 59 14 86 53 35 6 86 48 37 8 73 33 18 4 | 8 84 49 29 9 73 29 14 3 70 31 16 4 56 14 8 3 | 9 81 50 34 7 71 29 14 4 67 26 16 2 49 13 7 1 | A 65 29 16 4 51 17 5 2 48 13 6 2 24 6 4 1 | B 82 48 30 6 69 30 13 4 66 27 17 3 52 12 6 3 | C 65 25 15 3 49 14 8 3 47 13 9 2 27 7 4 1 | D 65 26 17 4 49 16 7 2 45 11 8 2 24 7 4 1 | E 44 13 9 2 28 7 3 1 23 3 5 3 15 3 2 0 | F Period 5 0 1 2 3 4 5 6 7 8 9 A B C D E F ---------------------------------------------------------------- 88 100 100 100 100 100 16 5 91 63 86 48 31 9 12 3 | 0 90 59 85 45 39 8 15 4 86 40 66 22 13 3 8 2 | 1 91 57 82 42 39 8 17 6 84 38 72 25 17 5 6 4 | 2 81 35 69 19 21 3 6 3 71 19 48 13 9 3 4 1 | 3 91 64 90 42 40 12 20 4 85 42 74 27 15 3 6 3 | 4 86 33 69 22 18 6 9 3 66 23 53 13 9 3 3 1 | 5 83 32 74 24 22 4 7 3 70 21 47 11 9 2 6 2 | 6 66 19 45 11 7 2 5 1 43 10 22 6 4 2 2 1 | 7 92 60 88 48 44 8 21 5 90 46 77 27 24 4 10 2 | 8 85 39 76 25 24 11 10 3 70 26 51 16 10 4 3 2 | 9 83 35 73 26 25 4 12 4 70 20 54 12 12 3 5 2 | A 69 24 48 12 9 3 4 1 45 11 32 5 4 4 3 1 | B 81 39 72 28 25 6 8 3 75 25 59 13 11 4 6 2 | C 65 21 51 10 13 5 5 2 50 12 33 6 4 1 2 1 | D 65 19 51 11 11 1 3 3 48 13 30 10 5 2 3 1 | E 42 9 29 3 5 1 4 2 22 4 12 3 2 1 3 0 | F Period 9 0 1 2 3 4 5 6 7 8 9 A B C D E F ---------------------------------------------------------------- 94 100 100 100 100 100 100 100 100 100 28 12 43 11 20 4 | 0 94 84 92 64 93 77 87 51 60 12 31 7 32 8 16 4 | 1 94 82 92 64 92 72 85 41 64 12 36 9 33 9 17 4 | 2 93 71 87 49 90 52 83 35 35 6 17 4 14 3 8 4 | 3 94 84 92 63 92 73 85 47 66 14 35 8 36 7 19 4 | 4 94 76 89 53 89 53 82 31 41 8 15 4 15 4 8 1 | 5 93 65 88 36 88 46 76 25 40 11 23 3 16 2 10 3 | 6 89 46 78 26 80 31 58 14 21 4 8 2 8 2 4 2 | 7 93 84 93 68 93 69 92 47 68 13 34 8 35 7 15 4 | 8 93 73 90 49 91 55 80 29 40 7 21 3 17 4 8 3 | 9 93 66 90 46 89 49 77 29 47 8 21 3 15 3 8 2 | A 90 54 82 30 79 34 62 19 21 5 7 3 8 2 4 1 | B 94 61 92 44 90 51 77 26 46 6 19 4 18 3 11 2 | C 90 51 79 28 85 34 66 14 23 4 7 4 8 3 4 1 | D 90 37 80 23 81 28 57 13 19 4 9 3 8 2 5 1 | E 82 26 57 13 66 18 33 7 9 3 4 1 5 2 2 1 | F I imagine the probability tables can be reduced down to a simple formula. Would save 256*3 bytes in my emulator... Date: Sat, 31 Mar 2007 23:11:20 -0500 From: Blargg:; To: anomie:; Subject: Re: S-DSP research Oh yeah, the first few probability entries in each table are junk because the test couldn't properly determine them. So ignore them up to about 0x0B.